package com.crk.yiyuanguahao.controller;

import com.crk.yiyuanguahao.entity.Doctor;
import com.crk.yiyuanguahao.service.DoctorService;
import com.crk.yiyuanguahao.util.LayUiTableJson;
import com.crk.yiyuanguahao.util.Page;
import com.crk.yiyuanguahao.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author
 * @description:
 * @date 2020/3/26
 */
@RestController
@RequestMapping("doctor")
public class DoctorController {

    @Autowired
    DoctorService doctorService;

    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/doctor/doctorList.html");
        return modelAndView;
    }

    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/doctor/doctorAdd.html");
        return modelAndView;
    }

    @RequestMapping("saveDoctor")
    public ResponseResult saveDoctor(Doctor doctor){
        return doctorService.saveDoctor(doctor);
    }

    @RequestMapping("deleteDoctor")
    public ResponseResult deleteDoctor(@RequestParam("id") Integer id){
        return doctorService.deleteDoctor(id);
    }

    @RequestMapping("getDoctor")
    public ResponseResult getDoctor(@RequestParam("id") Integer id){
        return doctorService.getDoctor(id);
    }

    @RequestMapping("getDoctorDetail")
    public ResponseResult getDoctorDetail(@RequestParam("doctorCode") String doctorCode){
        return doctorService.getDoctorDetail(doctorCode);
    }

    @RequestMapping("queryDoctorPage")
    public LayUiTableJson queryDoctorPage(String doctorCode,String doctorName, @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = doctorService.queryDoctorPage(doctorCode,doctorName,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("queryDoctorByOrg")
    public ResponseResult queryDoctorByOrg(Integer orgId,String keyword){
        return doctorService.queryDoctorByOrg(orgId, keyword);
    }

    @GetMapping("getDoctorList")
    public ResponseResult getDoctorList(int orgId){
        return doctorService.getDoctorList(orgId);
    }

    @GetMapping("getDetailTimeList")
    public ResponseResult getDetailTimeList(){
        return doctorService.getDetailTimeList();
    }
}
